-
Notifications
You must be signed in to change notification settings - Fork 381
version: add update notifications, json output
#2421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Implements version update notifications similar to Terraform's pattern. When running tflint --version, users see a notification if a newer version is available on GitHub Releases. ## Changes - Adds `versioncheck` package that checks GitHub Releases API for latest version - Modifies `--version` command to display update notifications when newer version available - Adds `--format json` support to version command with structured output including update status - Supports `TFLINT_DISABLE_VERSION_CHECK` environment variable to opt out - Caches version check results for 48 hours in platform-specific cache directory ## Implementation Details Version checking happens on every `--version` invocation with a 3-second timeout. Results are cached in the OS cache directory (`~/Library/Caches/tflint` on macOS, `~/.cache/tflint` on Linux) for 48 hours to minimize API calls. The check uses GitHub's public API (60 req/hour unauthenticated) or `GITHUB_TOKEN` environment variable for higher rate limits (5000 req/hour). Errors are logged but non-fatal - network timeouts or API failures don't break the version command. ## Testing Verified version checking against live GitHub API with both outdated and current versions. Cache behavior tested with 48-hour TTL validation. JSON output structure validated for both text and JSON formats. Closes #883
version: add update notifications
version: add update notificationsversion: add update notifications, json output
Clarify the usage of TFLINT_DISABLE_VERSION_CHECK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements version update notifications for TFLint, similar to Terraform's approach. When running tflint --version, users are notified if a newer version is available on GitHub Releases. The implementation includes JSON output support via --format json and can be disabled using the TFLINT_DISABLE_VERSION_CHECK environment variable.
Key changes:
- Adds version checking with GitHub Releases API integration (60 req/hour unauthenticated, 5000 req/hour with
GITHUB_TOKEN) - Implements 48-hour caching in platform-specific cache directories to minimize API calls
- Adds JSON output format for version command with structured update information
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| versioncheck/github.go | Implements GitHub API integration to fetch latest release version with optional authentication and rate limit handling |
| versioncheck/check.go | Core version checking logic with caching support and version comparison |
| versioncheck/check_test.go | Unit tests for Enabled() and compareVersions() functions |
| versioncheck/cache.go | Cache management with 48-hour TTL using platform-specific cache directories |
| versioncheck/cache_test.go | Unit tests for cache expiration logic |
| cmd/version.go | Integrates version checking into --version command with text and JSON output formats |
| docs/user-guide/environment_variables.md | Documents TFLINT_DISABLE_VERSION_CHECK environment variable |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix rate limit check in GitHub API error handling - Remove misleading comment about error handling - Add boundary checks in tests to prevent panics - Expand test coverage for version comparison and environment variables - Document GITHUB_TOKEN environment variable - Make GitHub client testable with httptest
Addresses errcheck linter violation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add update_check_enabled field to JSON output for clarity - Remove unused test variables in github_test.go - Consolidate notification message for thread safety - Make version check async for text format to improve responsiveness
Adds comprehensive integration tests that verify: - Recursive mode populates modules array with per-directory plugins - Top-level plugins field contains deduplicated plugins across all modules - Deduplication works correctly (aws in root + module1 = 1 entry) - Different plugins across modules are included (aws + google = 2 entries) - Plugins are sorted by name, then version - Non-recursive mode maintains backwards compatibility (no modules field) - Text format output works correctly Tests use real plugin downloads via --init to validate actual behavior.
Implements version update notifications similar to Terraform. When running
tflint --version, users now see a notification if a newer version is available on GitHub Releases.Changes
versioncheckpackage that checks GitHub Releases API for latest version--versioncommand to display update notifications when newer version available--format jsonsupport to version command with structured output including update statusTFLINT_DISABLE_VERSION_CHECKenvironment variable to opt outImplementation Details
Version checking happens asynchronously for text output (prints version immediately, shows update after plugins). JSON format performs synchronous check to ensure complete data in single output.
Results are cached in the OS cache directory (
~/Library/Caches/tflinton macOS,~/.cache/tflinton Linux) for 48 hours to minimize API calls.The check uses GitHub's public API (60 req/hour unauthenticated) or
GITHUB_TOKENenvironment variable for higher rate limits (5000 req/hour).Errors are logged but non-fatal - network timeouts or API failures don't break the version command.
JSON Output
JSON output includes
update_check_enabledfield to distinguish between disabled checking vs. no update available:update_check_enabled: false→ checking disabled via env varupdate_check_enabled: true, update_available: false→ no update or check failedupdate_check_enabled: true, update_available: true→ update availableTesting
Verified version checking against live GitHub API with both outdated and current versions. Added unit testing against the internals.
References
Closes #883